package com.zrar.ak.gkpt.controller.record;

import com.zrar.ak.gkpt.model.vo.UserVO;
import com.zrar.ak.gkpt.service.record.IBusinessVerifyInfoService;
import com.zrar.ak.gkpt.service.user.IUserService;
import com.zrar.ak.gkpt.util.FormDataParameter;
import com.zrar.ak.gkpt.util.JsonPageResult;
import com.zrar.ak.gkpt.util.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName: BusinessTestVerifyInfoController
 * @Description: 测试验证controller层
 * @Author: CaoTao
 * @Create: 2020/04/07
 */
@RestController
@RequestMapping("/verify")
@Api(tags = "测试验证信息相关接口")
public class BusinessTestVerifyInfoController {
    @Autowired
    private IBusinessVerifyInfoService verifyInfoService;
    @Autowired
    private IUserService userService;

    @RequestMapping(value = "save", method = RequestMethod.POST, produces = {"application/json;charset = utf-8"})
    @ApiOperation(value = "保存测试验证基本信息", httpMethod = "POST", notes = "保存测试验证基本信息")
    public JsonResult verifyInfoSave(HttpServletRequest request, @ApiParam(name = "formDataParameter",
            value = "测试验证基本信息参数") @RequestBody FormDataParameter formDataParameter) {
        JsonResult jsonResult = new JsonResult();
        String formDataJson = formDataParameter.getFormDataJson();
        UserVO userVo = userService.getUserInformation(request);
        jsonResult = verifyInfoService.verifyInfoSave(jsonResult, formDataJson, userVo);
        return jsonResult;
    }

    @RequestMapping(value = "delete", method = RequestMethod.DELETE, produces = {"application/json;charset = utf-8"})
    @ApiOperation(value = "删除测试验证基本信息", httpMethod = "DELETE", notes = "根据主键id修改测试验证基本信息状态码")
    public JsonResult verifyInfoDelete(@ApiParam(name = "id", value = "测试验证表主键Id") @RequestParam(name="id") String id) {
        JsonResult jsonResult = new JsonResult();
        jsonResult = verifyInfoService.deleteVerifyInfoById(jsonResult, id);
        return jsonResult;
    }

    @RequestMapping(value = "update", method = RequestMethod.PUT, produces = {"application/json;charset = utf-8"})
    @ApiOperation(value = "更新测试验证基本信息", httpMethod = "PUT", notes = "更新测试验证基本信息")
    public JsonResult verifyInfoUpdate(HttpServletRequest request, @ApiParam(name = "formDataParameter",
            value = "测试验证基本信息参数") @RequestBody FormDataParameter formDataParameter) {
        JsonResult jsonResult = new JsonResult();
        String formDataJson = formDataParameter.getFormDataJson();
        UserVO userVo = userService.getUserInformation(request);
        jsonResult = verifyInfoService.verifyInfoUpdate(jsonResult, formDataJson, userVo);
        return jsonResult;
    }

    @RequestMapping(value = "query", method = RequestMethod.GET, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "根据主键id获取测试验证信息", httpMethod = "GET", notes = "根据主键id获取测试验证信息")
    public JsonResult verifyInfoGetByunitId(@ApiParam(name = "id", value = "主键id")
                                                    @RequestParam(value = "id") String id) {
        JsonResult jsonResult = new JsonResult();
        System.out.println("测试id---"+id);
        jsonResult = verifyInfoService.queryVerifyInfoById(jsonResult,id);
        return jsonResult;
    }

    @RequestMapping(value = "list", method = RequestMethod.GET, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "获取测试验证信息列表-分页查询和条件查询", httpMethod = "GET", notes = "获取测试验证信息列表-分页查询和条件查询")
    public JsonPageResult getverifyInfoList(HttpServletRequest request,
                                             @ApiParam(name = "currentPage", value = "当前页") @RequestParam int currentPage,
                                             @ApiParam(name = "pageSize", value = "每页条数限制") @RequestParam int pageSize,
                                             @ApiParam(name = "unitName", value = "建设单位名称(模糊查询)") @RequestParam(value = "unitName", required = false) String unitName) {
        JsonPageResult jsonResult = new JsonPageResult();
        jsonResult = verifyInfoService.getVerifyInfoList(jsonResult, currentPage, pageSize, unitName);
        return jsonResult;
    }
}
